﻿
namespace NetROS.Tiers.Windows.Forms
{
	/// <summary>
	/// abstract PrilagodenDokumentTip typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class PrilagodenDokumentTipDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<PrilagodenDokumentTipDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.PrilagodenDokumentTip _currentPrilagodenDokumentTip = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxPrilagodenDokumentTipDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxPrilagodenDokumentTipErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxPrilagodenDokumentTipBindingSource;
		
		/// <summary> 
		/// the DGV column associated with the IDDokumentTip property
		/// </summary>
		protected System.Windows.Forms.DataGridViewComboBoxColumn uxIDDokumentTipDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Naziv property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxNazivDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the SkraceniNaziv property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxSkraceniNazivDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Parametar1 property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxParametar1DataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Parametar2 property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxParametar2DataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Parametar3 property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxParametar3DataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
				
		private Entities.TList<Entities.DokumentTip> _IDDokumentTipList;
		
		/// <summary> 
		/// The list of selectable DokumentTip
		/// </summary>
		[System.ComponentModel.Category("DropDownList BindingSources")]
		public Entities.TList<Entities.DokumentTip> IDDokumentTipList
		{
			get {return this._IDDokumentTipList;}
			set 
			{
				this._IDDokumentTipList = value;
				this.uxIDDokumentTipDataGridViewColumn.DataSource = null;
				this.uxIDDokumentTipDataGridViewColumn.DataSource = this._IDDokumentTipList;
			}
		}
		
		private bool _allowNewItemInIDDokumentTipList;
		
		/// <summary> 
		/// Indicates if user can add an item in the list of DokumentTip
		/// </summary>
		[System.ComponentModel.Category(".netTiers"), System.ComponentModel.Description("Indicates if end user can add a new item in the combobox. an event will be thrown then.")]
		public bool AllowNewItemInIDDokumentTipList
		{
			get { return _allowNewItemInIDDokumentTipList;}
			set
			{
				this._allowNewItemInIDDokumentTipList = value;
				this.uxIDDokumentTipDataGridViewColumn.DisplayStyle = value ? System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox : System.Windows.Forms.DataGridViewComboBoxDisplayStyle.DropDownButton;
			}
		}
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.PrilagodenDokumentTip> _PrilagodenDokumentTipList;
				
		/// <summary> 
		/// The list of PrilagodenDokumentTip to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.PrilagodenDokumentTip> PrilagodenDokumentTipList
		{
			get {return this._PrilagodenDokumentTipList;}
			set
			{
				this._PrilagodenDokumentTipList = value;
				this.uxPrilagodenDokumentTipBindingSource.DataSource = null;
				this.uxPrilagodenDokumentTipBindingSource.DataSource = value;
				this.uxPrilagodenDokumentTipDataGridView.DataSource = null;
				this.uxPrilagodenDokumentTipDataGridView.DataSource = this.uxPrilagodenDokumentTipBindingSource;				
				//this.uxPrilagodenDokumentTipBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxPrilagodenDokumentTipBindingSource_ListChanged);
				this.uxPrilagodenDokumentTipBindingSource.CurrentItemChanged += new System.EventHandler(OnPrilagodenDokumentTipBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnPrilagodenDokumentTipBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentPrilagodenDokumentTip = uxPrilagodenDokumentTipBindingSource.Current as Entities.PrilagodenDokumentTip;
			
			if (_currentPrilagodenDokumentTip != null)
			{
				_currentPrilagodenDokumentTip.Validate();
			}
			//_PrilagodenDokumentTip.Validate();
			OnCurrentEntityChanged();
		}

		//void uxPrilagodenDokumentTipBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.PrilagodenDokumentTip"/> instance.
		/// </summary>
		public Entities.PrilagodenDokumentTip SelectedPrilagodenDokumentTip
		{
			get {return this._currentPrilagodenDokumentTip;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxPrilagodenDokumentTipDataGridView.VirtualMode;}
			set
			{
				this.uxPrilagodenDokumentTipDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxPrilagodenDokumentTipDataGridView.AllowUserToAddRows;}
			set {this.uxPrilagodenDokumentTipDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxPrilagodenDokumentTipDataGridView.AllowUserToDeleteRows;}
			set {this.uxPrilagodenDokumentTipDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxPrilagodenDokumentTipDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxPrilagodenDokumentTipDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="PrilagodenDokumentTipDataGridViewBase"/> class.
		/// </summary>
		public PrilagodenDokumentTipDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxPrilagodenDokumentTipDataGridView = new System.Windows.Forms.DataGridView();
			this.uxPrilagodenDokumentTipBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxPrilagodenDokumentTipErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIDDokumentTipDataGridViewColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
			this.uxNazivDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxSkraceniNazivDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxParametar1DataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxParametar2DataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxParametar3DataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			//this.uxIDDokumentTipBindingSource = new DokumentTipBindingSource(this.components);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDDokumentTipBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxPrilagodenDokumentTipDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxPrilagodenDokumentTipBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxPrilagodenDokumentTipErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxPrilagodenDokumentTipErrorProvider
			// 
			this.uxPrilagodenDokumentTipErrorProvider.ContainerControl = this;
			this.uxPrilagodenDokumentTipErrorProvider.DataSource = this.uxPrilagodenDokumentTipBindingSource;						
			// 
			// uxPrilagodenDokumentTipDataGridView
			// 
			this.uxPrilagodenDokumentTipDataGridView.AutoGenerateColumns = false;
			this.uxPrilagodenDokumentTipDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxPrilagodenDokumentTipDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIDDokumentTipDataGridViewColumn,
		this.uxNazivDataGridViewColumn,
		this.uxSkraceniNazivDataGridViewColumn,
		this.uxParametar1DataGridViewColumn,
		this.uxParametar2DataGridViewColumn,
		this.uxParametar3DataGridViewColumn			});
			this.uxPrilagodenDokumentTipDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxPrilagodenDokumentTipDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxPrilagodenDokumentTipDataGridView.Name = "uxPrilagodenDokumentTipDataGridView";
			this.uxPrilagodenDokumentTipDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxPrilagodenDokumentTipDataGridView.TabIndex = 0;	
			this.uxPrilagodenDokumentTipDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxPrilagodenDokumentTipDataGridView.EnableHeadersVisualStyles = false;
			this.uxPrilagodenDokumentTipDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnPrilagodenDokumentTipDataGridViewDataError);
			this.uxPrilagodenDokumentTipDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnPrilagodenDokumentTipDataGridViewCellValueNeeded);
			this.uxPrilagodenDokumentTipDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnPrilagodenDokumentTipDataGridViewCellValuePushed);
			
			//
			// uxIDDokumentTipDataGridViewColumn
			//
			this.uxIDDokumentTipDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIDDokumentTipDataGridViewColumn.DataPropertyName = "IDDokumentTip";
			this.uxIDDokumentTipDataGridViewColumn.HeaderText = "IDDokumentTip";
			this.uxIDDokumentTipDataGridViewColumn.Name = "uxIDDokumentTipDataGridViewColumn";
			this.uxIDDokumentTipDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIDDokumentTipDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIDDokumentTipDataGridViewColumn.ReadOnly = false;		
			//
			// uxNazivDataGridViewColumn
			//
			this.uxNazivDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxNazivDataGridViewColumn.DataPropertyName = "Naziv";
			this.uxNazivDataGridViewColumn.HeaderText = "Naziv";
			this.uxNazivDataGridViewColumn.Name = "uxNazivDataGridViewColumn";
			this.uxNazivDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxNazivDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxNazivDataGridViewColumn.ReadOnly = false;		
			//
			// uxSkraceniNazivDataGridViewColumn
			//
			this.uxSkraceniNazivDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxSkraceniNazivDataGridViewColumn.DataPropertyName = "SkraceniNaziv";
			this.uxSkraceniNazivDataGridViewColumn.HeaderText = "SkraceniNaziv";
			this.uxSkraceniNazivDataGridViewColumn.Name = "uxSkraceniNazivDataGridViewColumn";
			this.uxSkraceniNazivDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxSkraceniNazivDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxSkraceniNazivDataGridViewColumn.ReadOnly = false;		
			//
			// uxParametar1DataGridViewColumn
			//
			this.uxParametar1DataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxParametar1DataGridViewColumn.DataPropertyName = "Parametar1";
			this.uxParametar1DataGridViewColumn.HeaderText = "Parametar1";
			this.uxParametar1DataGridViewColumn.Name = "uxParametar1DataGridViewColumn";
			this.uxParametar1DataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxParametar1DataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxParametar1DataGridViewColumn.ReadOnly = false;		
			//
			// uxParametar2DataGridViewColumn
			//
			this.uxParametar2DataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxParametar2DataGridViewColumn.DataPropertyName = "Parametar2";
			this.uxParametar2DataGridViewColumn.HeaderText = "Parametar2";
			this.uxParametar2DataGridViewColumn.Name = "uxParametar2DataGridViewColumn";
			this.uxParametar2DataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxParametar2DataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxParametar2DataGridViewColumn.ReadOnly = false;		
			//
			// uxParametar3DataGridViewColumn
			//
			this.uxParametar3DataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxParametar3DataGridViewColumn.DataPropertyName = "Parametar3";
			this.uxParametar3DataGridViewColumn.HeaderText = "Parametar3";
			this.uxParametar3DataGridViewColumn.Name = "uxParametar3DataGridViewColumn";
			this.uxParametar3DataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxParametar3DataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxParametar3DataGridViewColumn.ReadOnly = false;		
			//
			// uxIDDokumentTipDataGridViewColumn
			//				
			this.uxIDDokumentTipDataGridViewColumn.DisplayMember = "Naziv";	
			this.uxIDDokumentTipDataGridViewColumn.ValueMember = "ID";	
			this.uxIDDokumentTipDataGridViewColumn.DisplayStyleForCurrentCellOnly = true;
			//uxIDDokumentTipDataGridViewColumn.DataSource = uxIDDokumentTipBindingSource;				
				
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxPrilagodenDokumentTipDataGridView);
			this.Name = "PrilagodenDokumentTipDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			//((System.ComponentModel.ISupportInitialize)(this.uxIDDokumentTipBindingSource)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxPrilagodenDokumentTipErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxPrilagodenDokumentTipDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxPrilagodenDokumentTipBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				PrilagodenDokumentTipDataGridViewEventArgs args = new PrilagodenDokumentTipDataGridViewEventArgs();
				args.PrilagodenDokumentTip = _currentPrilagodenDokumentTip;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class PrilagodenDokumentTipDataGridViewEventArgs : System.EventArgs
		{
			private Entities.PrilagodenDokumentTip	_PrilagodenDokumentTip;
	
			/// <summary>
			/// the  Entities.PrilagodenDokumentTip instance.
			/// </summary>
			public Entities.PrilagodenDokumentTip PrilagodenDokumentTip
			{
				get { return _PrilagodenDokumentTip; }
				set { _PrilagodenDokumentTip = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxPrilagodenDokumentTipDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnPrilagodenDokumentTipDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxPrilagodenDokumentTipDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnPrilagodenDokumentTipDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxPrilagodenDokumentTipDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDokumentTipDataGridViewColumn":
						e.Value = PrilagodenDokumentTipList[e.RowIndex].IDDokumentTip;
						break;
					case "uxNazivDataGridViewColumn":
						e.Value = PrilagodenDokumentTipList[e.RowIndex].Naziv;
						break;
					case "uxSkraceniNazivDataGridViewColumn":
						e.Value = PrilagodenDokumentTipList[e.RowIndex].SkraceniNaziv;
						break;
					case "uxParametar1DataGridViewColumn":
						e.Value = PrilagodenDokumentTipList[e.RowIndex].Parametar1;
						break;
					case "uxParametar2DataGridViewColumn":
						e.Value = PrilagodenDokumentTipList[e.RowIndex].Parametar2;
						break;
					case "uxParametar3DataGridViewColumn":
						e.Value = PrilagodenDokumentTipList[e.RowIndex].Parametar3;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxPrilagodenDokumentTipDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnPrilagodenDokumentTipDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxPrilagodenDokumentTipDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIDDokumentTipDataGridViewColumn":
						PrilagodenDokumentTipList[e.RowIndex].IDDokumentTip = (System.Int32)e.Value;
						break;
					case "uxNazivDataGridViewColumn":
						PrilagodenDokumentTipList[e.RowIndex].Naziv = (System.String)e.Value;
						break;
					case "uxSkraceniNazivDataGridViewColumn":
						PrilagodenDokumentTipList[e.RowIndex].SkraceniNaziv = (System.String)e.Value;
						break;
					case "uxParametar1DataGridViewColumn":
						PrilagodenDokumentTipList[e.RowIndex].Parametar1 = (System.String)e.Value;
						break;
					case "uxParametar2DataGridViewColumn":
						PrilagodenDokumentTipList[e.RowIndex].Parametar2 = (System.String)e.Value;
						break;
					case "uxParametar3DataGridViewColumn":
						PrilagodenDokumentTipList[e.RowIndex].Parametar3 = (System.String)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
